package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.UploadInfo;
import com.stylefeng.guns.modular.system.service.IUploadInfoService;

/**
 * 上传信息控制器
 *
 * @author fengshuonan
 * @Date 2018-09-26 16:10:00
 */
@Controller
@RequestMapping("/uploadInfo")
public class UploadInfoController extends BaseController {

    private String PREFIX = "/system/uploadInfo/";

    @Autowired
    private IUploadInfoService uploadInfoService;

    /**
     * 跳转到上传信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "uploadInfo.html";
    }

    /**
     * 跳转到添加上传信息
     */
    @RequestMapping("/uploadInfo_add")
    public String uploadInfoAdd() {
        return PREFIX + "uploadInfo_add.html";
    }

    /**
     * 跳转到修改上传信息
     */
    @RequestMapping("/uploadInfo_update/{uploadInfoId}")
    public String uploadInfoUpdate(@PathVariable Integer uploadInfoId, Model model) {
        UploadInfo uploadInfo = uploadInfoService.selectById(uploadInfoId);
        model.addAttribute("item",uploadInfo);
        LogObjectHolder.me().set(uploadInfo);
        return PREFIX + "uploadInfo_edit.html";
    }

    /**
     * 获取上传信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return uploadInfoService.selectList(null);
    }

    /**
     * 新增上传信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UploadInfo uploadInfo) {
        uploadInfoService.insert(uploadInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除上传信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer uploadInfoId) {
        uploadInfoService.deleteById(uploadInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改上传信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UploadInfo uploadInfo) {
        uploadInfoService.updateById(uploadInfo);
        return SUCCESS_TIP;
    }

    /**
     * 上传信息详情
     */
    @RequestMapping(value = "/detail/{uploadInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("uploadInfoId") Integer uploadInfoId) {
        return uploadInfoService.selectById(uploadInfoId);
    }
}
